Overview

By now, you have created a back-end Django application containing a project called LittleLemon , and an app called Restaurant . You have also configured the application to use a MySQL database.

In this exercise, you will create the Menu and Booking models for the Restaurant app and migrate them to the MySQL database tables of the same name.

Scenario

By the end of this project, you will have built REST APIs for ordering food using the Menu API and reserving the table using the Booking API.

You will build these APIs based on the Menu and Booking models using the model schema provided to you.

Booking table

Menu table

Prerequisites

Ensure that you have created a Django virtual environment, and inside it, a project called LittleLemon . Inside the project, make sure you have an app called Restaurant .

You also need to have the MySQL server running with the LittleLemon database.

Steps

Step 1: Declare Menu and Booking models

Refer to the table schema for the Menu and Booking tables provided to you. Declare the menu and booking model classes with matching attributes.

You must save the code for these classes in the models.py file under the restaurant app package folder.

Step 2: perform migrations

First, run the makemigrations command of the manage.py script .

Then run the command python manage.py migrate .

The corresponding tables will be created in the database.

Confirm that tables are created using the MySQL browser extension you installed earlier in VS Code.

Step 3: Register the models in admin module

Open the admin.py file and register the Menu and Booking models with the admin site using the admin.site.register() method.

Step 4: Add data in models

Login to the admin panel with the superuser created earlier.

Add some data in Menu and Booking models using the admin interface.

Step 5: Check the data in VS Code

Refresh the MySQL browser in VS Code to display the data added through the admin interface.

Conclusion

In this exercise, you successfully declared the models for restaurant app and migrated to the MySQL database.